﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KingRoad.EPM.SafetyManagementBLL.Domain;
using KingRoad.EPM.SafetyManagementEntity.Model;
using KingRoad.EPM.SafetyManagementDAL.BfUserService;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.SafetyManagementDAL.PlmPersonLeaveService;


namespace KingRoad.EPM.SafetyManagementBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/4/5 4:46:30
    /// </summary> 
    public class CommonFileUIRule
    {
        private readonly ICommonFileService _commonFileService;


        public CommonFileUIRule() { }

        /// <summary> 
        /// construct function... 
        /// </summary> 
        public CommonFileUIRule(ICommonFileService commonFileService)
        {
            _commonFileService = commonFileService;
        }

        /// <summary>
        /// 批量插入附件
        /// </summary>
        /// <param name="bizId">业务ID（对应具体表AssisId）</param>
        /// <param name="bizType">业务编码</param>
        /// <param name="fileIds">文件IDS</param>
        /// <returns>返回插入CommonFile表后，返回的主键IDs</returns>
        public string BatchAddAttach(int bizId, string bizType, string fileIds)
        {
            List<CommonFileInfo> list = new List<CommonFileInfo>();
            fileIds.Split(',').ToList().ForEach(t =>
            {
                list.Add(new CommonFileInfo
                {
                    FILE_TYPE = bizType,
                    FILE_FILEID = Convert.ToInt32(t),
                    FILE_TYPEID = bizId,
                });
            });

            var ret = _commonFileService.BatchAddAttach(list);
            return ret;
        }

        /// <summary>
        /// 查询附件信息
        /// </summary>
        /// <param name="bizId">业务ID（对应具体表AssisId,也对应COMMON_FILE表FILE_TYPEID）</param>
        /// <param name="bizType">对应表COMMON_FILE中的FILE_TYPE</param>
        /// <returns></returns>
        public List<CommonFileInfo> GetCommonFilesByConditon(int bizId, string bizType)
        {
            var strSql = String.Format(" FILE_TYPE='{0}' AND FILE_TYPEID={1} ", bizType, bizId);
            var ret = _commonFileService.GetEntityList(strSql);
            return ret;
        }
        /// <summary>
        /// 删除附件信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteCommonFile(int id)
        {
            var ret = _commonFileService.DeleteEntityByStringID(id.ToString());
            return ret > 0;
        }
    }
}

